/*
ID: icerupt1
PROG: dualpal
LANG: C++11
*/
#include <fstream>
#include <algorithm>
#include <string>
using namespace std;

string base_change(int x, int b)
{
	string s = "";
	while (x) {
		if (x%b >= 10) s += 'A' + x%b - 10;
		else		   s += '0' + x%b;
		x /= b;
	}
	reverse(s.begin(), s.end());
	return s;
}

bool is_palsquare(string s)
{
	return s == string(s.rbegin(), s.rend());
}

int main()
{
	ifstream fin {"dualpal.in" };
	ofstream fout{"dualpal.out"};
	int n, s;
	fin >> n >> s;
	for (int i = 1, count = 0; count < n; i++) {
		int time = 0;
		for (int j = 2; j <= 10 && time < 2; j++)
			if (is_palsquare(base_change(s+i, j))) time++;
		if (time >= 2) { fout << s+i << "\n"; count++; }
	}
}

